package player;

import java.util.List;
import java.util.Observable;
import java.util.Vector;

import server.Card;
/**
 * This class manages the data about the game that is needed to be shown by the user interface.
 * 
 * This class it is a part of a Observable/Observer pattern.
 * This class is the observable, the Player User Interface class (PlayerUI) is the observer.
 * Any change in this class, will fire the Update method of PlayerUI.
 * 
 */
public class GameData extends Observable {
	private List<Card> myCards = new Vector<Card>();
	private List<Card> cardsOnTable = new Vector<Card>();
	private int[] score = new int[4];
	private int id=0;
	private String textShown="";
	private boolean permissionToPlay=true;
	private int turnIndex;
	private int maxScore=40;
	private boolean endApp=false;
	
	
	public String getTextShown() {
		return textShown;
	}
	
	
	public boolean isEndApp() {
		return this.endApp;
	}
	
	public void endApp() {
		this.endApp=true;
		this.setChanged();
		this.notifyObservers();
	}
	
	
	public void enablePermissionToPlay(){
		this.permissionToPlay=true;
		this.setChanged();
		this.notifyObservers();
	}

	public void disablePermissionToPlay(){
		this.permissionToPlay=false;
		this.setChanged();
		this.notifyObservers();
	}
	
	// GETTERS & SETTERS
	
	public int getMaxScore() {
		return this.maxScore;
	}
	
	public void setTextShown(String textShown) {
		this.textShown = textShown;
		this.setChanged();
		this.notifyObservers();
	}
	public List<Card> getMyCards() {
		return myCards;
	}
	
	
	public void setMyCards(List<Card> newCards) {
		
		Object[] newc = newCards.toArray();
		
		this.myCards.clear();
		
		for (Object card : newc) {
			this.myCards.add((Card)card);	
		}
		
		this.setChanged();
		this.notifyObservers();
	}
	
	public void clearMyCards() {
		
		this.myCards.clear();
		this.setChanged();
		this.notifyObservers();
	}

	public void clearCardsOnTable() {
		
		this.cardsOnTable.clear();
		this.setChanged();
		this.notifyObservers();
	}

	
	public List<Card> getCardsOnTable() {
		return cardsOnTable;
	}
	public void setCardsOnTable(List<Card> cardsOnTable) {
		Object[] newc = cardsOnTable.toArray();
		
		this.cardsOnTable.clear();
		
		for (Object card : newc) { this.cardsOnTable.add((Card)card); }
		
		this.setChanged();
		this.notifyObservers();
	}
	public int getScore(int player) {
		return score[player];
	}
	public void setScore(int player,int score) {
		this.score[player] = score;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
		this.setChanged();
		this.notifyObservers();
	}

	public boolean havePermissionToplay() {
		return this.permissionToPlay;
	}

	public void setTurnIndex(int size) {
		this.turnIndex = size;
		
	}

	public int getTurnIndex() {
		return this.turnIndex;
	}

	public int numberOfCardsOnTable() {
		return this.cardsOnTable.size();
	}


	public void clearScores() {
		for (int i=0;i<4;i++) {
			this.score[i]=0;
		}
		
	}
	
	
}
